package com.anysoft.web;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;

import com.anysoft.HostConstant;
import com.anysoft.me.base.BaseWebViewActivity;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;

/**
 * Created by lty on 2018/4/16.
 * 招行鉴权 - 验证银行卡
 */

public class MerChantsBankActivity extends BaseWebViewActivity {

    private String returnUrl;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isShowTitleBar(true);
        String formContent = getIntent().getStringExtra("formContent");
        returnUrl = getIntent().getStringExtra("returnUrl");
        if (StringUtils.isNullOrEmpty(formContent))
            return;
        loadUrl = formContent;
        title.setText("验证银行卡");
        if (CommonUtil.isNetWorkConnected(this)) {
            setWebViewConfig(loadUrl);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onshouldOverrideUrlLoadingCallBack(WebView webview, String url) {
        String url_decode = null;
        try {
            url_decode = URLDecoder.decode(url, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (url.contains(returnUrl)){
            HashMap<String, String> param = processParam(url_decode.split("\\?")[1]);
            String status = param.get("status");
            Intent intent = new Intent();
            intent.putExtra("status", status);
            setResult(HostConstant.RESULT_CHANTS_BANK, intent);
            finish();
        } else {
            webview.loadUrl(url);
        }
    }
}
